home *** CD-ROM | disk | FTP | other *** search
/ Total Web Page (Professional Suite) / Total Web Page 99.iso / CGI / C_DOWNLOAD.CGI-S=TEXTCLOCK&C=TXT&F=TCLOCK.CPP < prev    next >
Text File  |  1996-06-03  |  4KB  |  135 lines

  1. #include <iostream.h>
  2. #include <string.h>
  3. #include <time.h>
  4. /*****************************************************************************
  5. * TextClock  (C++ Version)      Version 1.0.3                                *
  6. * Copyright 1996 Matt Wright    mattw@worldwidemart.com                      *
  7. * Created 07/15/96              Last Modified 03/29/97                       *
  8. * Matt's Script Archive, Inc.   http://www.worldwidemart.com/scripts/        *
  9. ******************************************************************************
  10. * COPYRIGHT NOTICE                                                           *
  11. * Copyright 1996 Matthew M. Wright  All Rights Reserved.                     *
  12. *                                                                            *
  13. * TextClock may be used and modified free of charge by anyone so long as     *
  14. * this copyright notice and the comments above remain intact.  By using this *
  15. * code you agree to indemnify Matthew M. Wright from any liability that      *
  16. * might arise from it's use.                                                 *
  17. *                                                                            *
  18. * Selling the code for this program without prior written consent is         *
  19. * expressly forbidden.  In other words, please ask first before you try and  *
  20. * make money off of my program.                                              *
  21. *                                                                            *
  22. * Obtain permission before redistributing this software over the Internet or *
  23. * in any other medium.  In all cases copyright and header must remain intact *
  24. *****************************************************************************/
  25. // Define Variables
  26.  
  27. const int Display_Week_Day = 1;
  28. const int Display_Month = 1;
  29. const int Display_Month_Day = 1;
  30. const int Display_Year = 1;
  31. const int Display_Time = 1;
  32. const int Display_Time_Zone = 1;
  33.  
  34. const char Standard_Time_Zone[4] = "EST";
  35. const char Daylight_Time_Zone[4] = "EDT";
  36.  
  37. const char Display_Link[] = "http://www.worldwidemart.com/scripts/";
  38.  
  39. // Done
  40. /****************************************************************************/
  41.  
  42. void main()
  43. {
  44.     char Week_Days[7][10] = { "Sunday", "Monday", "Tuesday", "Wednesday",
  45.                               "Thursday", "Friday", "Saturday" };
  46.     char Months[12][10] =   { "January", "February", "March", "April", "May", 
  47.                               "June", "July", "August", "September", 
  48.                               "October", "November", "December" };
  49.     char Time_Zone[4];
  50.  
  51.     tm *ptm;
  52.     time_t *cur_time;
  53.  
  54.     cout << "Content-type: text/html\n\n";
  55.  
  56.     if (strlen(Display_Link) > 0)
  57.         cout << "<a href=\"" << Display_Link << "\">";
  58.  
  59.     // Set up the memory for the time and time time struct.
  60.     cur_time = new time_t;
  61.     ptm = new tm;
  62.  
  63.     // Get the time, then create the struct with time values.
  64.     time(cur_time);
  65.     ptm = localtime(cur_time);
  66.  
  67.     // Determine whether it is daylight savings time or not.
  68.     if (ptm->tm_isdst)
  69.         strcat(Time_Zone,Daylight_Time_Zone);
  70.     else
  71.         strcat(Time_Zone,Standard_Time_Zone);
  72.  
  73.     // Display the day of the week if requested.
  74.     if (Display_Week_Day)
  75.     {
  76.         cout << Week_Days[ptm->tm_wday];
  77.  
  78.         if (Display_Month)
  79.             cout << ", ";
  80.     }
  81.  
  82.     // Display the name of the month if requested.
  83.     if (Display_Month)
  84.         cout << Months[ptm->tm_mon] << " ";
  85.  
  86.     // Display the day of the month if requested.
  87.     if (Display_Month_Day != 0) 
  88.     {
  89.         if (ptm->tm_mday < 10)
  90.             cout << "0";
  91.  
  92.         cout << ptm->tm_mday;
  93.  
  94.         if (Display_Year)
  95.             cout << ", ";
  96.     }
  97.  
  98.     // Display the year if requested.
  99.     if (Display_Year)
  100.     {
  101.         cout << ptm->tm_year + 1900;
  102.  
  103.         if (Display_Time)
  104.             cout << " - ";
  105.         else if (Display_Time_Zone)
  106.             cout << " ";
  107.     }
  108.  
  109.     // Display the time if requested.
  110.     if (Display_Time)
  111.     {
  112.         if (ptm->tm_hour < 10)
  113.             cout << "0";
  114.         cout << ptm->tm_hour << ":";
  115.  
  116.         if (ptm->tm_min < 10)
  117.             cout << "0";
  118.         cout << ptm->tm_min << ":";
  119.  
  120.         if (ptm->tm_sec < 10)
  121.             cout << "0";
  122.         cout << ptm->tm_sec;
  123.  
  124.         if (Display_Time_Zone)
  125.             cout << " ";
  126.     }
  127.  
  128.     // Display the time zone if requested.
  129.     if (Display_Time_Zone)
  130.         cout << Time_Zone;
  131.  
  132.     // Close the link if we linked the clock.
  133.     if (Display_Link)
  134.         cout << "</a>";
  135. }